#ifndef _X_SOCKET_H
#define _X_SOCKET_H
#include "xDef.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <unistd.h>
namespace xNet
{
    typedef enum SOCKET_STATE
    {
        SOCKET_STATE_NOT_INIT = 0,
        SOCKET_STATE_INITED,
        SOCKET_STATE_CONNECTED,
        SOCKET_STATE_DISCONNECTED,
        SOCKET_STATE_CLOSE
    }SOCKET_STATE;

    NET_ENGINE_CORE_API class xSocket
    {
        public:
            xSocket();
            xSocket(std::string strIp,uint16 wPort);
            ~xSocket();
        public:
            bool Init();
            void Close();
            void SetNonBlock();
        public:
            bool AddEPOLL(int epfd,void* ptr);
            bool DelEPOLL(int epfd);
            bool ModEPOLL(int epfd,int event);
        public:
            bool SendData(const void* data,int length);
            bool RecvData(void* data,int length);
        public:
            uint32 RecvPacket(void* data);
        private:
            MACRO_PROPERTY_DEF(int,m_dwFd,Fd)
            MACRO_PROPERTY_READONLY(std::string,m_strIp,Ip)
            MACRO_PROPERTY_READONLY(uint16,m_wPort,Port)
            MACRO_PROPERTY_DEF(SOCKET_STATE,m_state,State)
    };

    NET_ENGINE_CORE_API class xServiceSocket : public xSocket
    {
        public:
            xServiceSocket(std::string strIp,uint16 wPort);
        public:
            bool Bind();
            bool Listen();
            xSocket* Accept();
    };

    NET_ENGINE_CORE_API class xClientSocket : public xSocket
    {
        public:
            bool Connect();
            bool TryConnect();
            void DisConnect();
    };
}

#endif